package com.idig8.leetcode.链表;

public class _141_环形链表 {
    public class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }
    public boolean hasCycle(ListNode head) {
        if (head == null) return false;
        if (head.next == null) return false;

        ListNode slow = head;
        ListNode fast = head.next;

        if(fast != null && fast.next!= null){
            if(fast == slow) return true;
            slow = slow.next;
            fast = fast.next.next;
        }
        return  false;
    }
}
